﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.QcManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.QcManagement.QcTemplateVMs
{
    public partial class QcTemplateListVM : BasePagedListVM<QcTemplate_View, QcTemplateSearcher>
    {
        
        protected override IEnumerable<IGridColumn<QcTemplate_View>> InitGridHeader()
        {
            return new List<GridColumn<QcTemplate_View>>{
                
                this.MakeGridHeader(x => x.QcTemplate_Name).SetTitle(@Localizer["Page.模板名称"].Value),
                this.MakeGridHeader(x => x.QcTemplate_Code).SetTitle(@Localizer["Page.模板编码"].Value),
                this.MakeGridHeader(x => x.QcTemplate_ProductId).SetTitle(@Localizer["Page.检验产品"].Value),
                this.MakeGridHeader(x => x.QcTemplate_ProductionName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.QcTemplate_QcMode).SetTitle(@Localizer["Page.质检模式"].Value),
                this.MakeGridHeader(x => x.QcTemplate_Aux_1).SetTitle(@Localizer["Page.备注1"].Value),
                this.MakeGridHeader(x => x.QcTemplate_Aux_2).SetTitle(@Localizer["Page.备注2"].Value),
                this.MakeGridHeader(x => x.QcTemplate_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.QcTemplate_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.QcTemplate_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.QcTemplate_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<QcTemplate_View> GetSearchQuery()
        {
            var query = DC.Set<QcTemplate>()
                
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductionName, x=>x.ProductionName)
                .CheckEqual(Searcher.QcMode, x=>x.QcMode)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new QcTemplate_View
                {
				    ID = x.ID,
                    
                    QcTemplate_Name = x.Name,
                    QcTemplate_Code = x.Code,
                    QcTemplate_ProductId = x.ProductId,
                    QcTemplate_ProductionName = x.ProductionName,
                    QcTemplate_QcMode = x.QcMode,
                    QcTemplate_Aux_1 = x.Aux_1,
                    QcTemplate_Aux_2 = x.Aux_2,
                    QcTemplate_CreateTime = x.CreateTime,
                    QcTemplate_UpdateTime = x.UpdateTime,
                    QcTemplate_CreateBy = x.CreateBy,
                    QcTemplate_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class QcTemplate_View: QcTemplate
    {
        
        public string QcTemplate_Name { get; set; }
        public string QcTemplate_Code { get; set; }
        public long? QcTemplate_ProductId { get; set; }
        public string QcTemplate_ProductionName { get; set; }
        public QcModeEnum? QcTemplate_QcMode { get; set; }
        public string QcTemplate_Aux_1 { get; set; }
        public string QcTemplate_Aux_2 { get; set; }
        public DateTime? QcTemplate_CreateTime { get; set; }
        public DateTime? QcTemplate_UpdateTime { get; set; }
        public string QcTemplate_CreateBy { get; set; }
        public string QcTemplate_UpdateBy { get; set; }

    }

}